package hotkey

import (
	"log"
	"runtime"

	"clipPaste/internal/ui"

	hook "github.com/robotn/gohook"
)

type Manager struct {
	historyWin *ui.HistoryWindow
}

func NewManager(historyWin *ui.HistoryWindow) *Manager {
	return &Manager{
		historyWin: historyWin,
	}
}

func (m *Manager) StartListening() {
	go func() {
		log.Println("Starting hotkey listener...")

		// 注册热键事件
		hook.Register(hook.KeyDown, []string{"cmd", "shift", "v"}, func(e hook.Event) {
			if runtime.GOOS == "darwin" {
				log.Println("Hotkey triggered: Command+Shift+V")
				m.historyWin.Show()
			}
		})

		hook.Register(hook.KeyDown, []string{"ctrl", "shift", "v"}, func(e hook.Event) {
			if runtime.GOOS != "darwin" {
				log.Println("Hotkey triggered: Ctrl+Shift+V")
				m.historyWin.Show()
			}
		})

		s := hook.Start()
		<-hook.Process(s)
	}()
}
